package com.kerbores.kop.serverlet;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.nutz.json.Json;
import org.nutz.json.JsonFormat;
import org.nutz.lang.Strings;

import com.kerbores.utils.encode.DES;
import com.kerbores.utils.encode.KerboresDes;
import com.kerbores.utils.entries.Result;

public class ResponseUtils {

	public static void responseException(String info, HttpServletRequest request, HttpServletResponse response) throws IOException {
		Object obj = Result.exception(info);
		if (Strings.equalsIgnoreCase(request.getHeader("client"), "IOS")) {// 如果客户端是IOS
			response.getWriter().write(DES.encrypt(Json.toJson(obj, JsonFormat.compact())));
		} else { // Android和js调用
			response.getWriter().write(KerboresDes.enc(Json.toJson(obj, JsonFormat.compact())));
		}
	}
}
